package com.css.crm.dao.impl;

import org.apache.ibatis.session.SqlSession;

import com.css.crm.dao.CustomerDao;
import com.css.crm.vo.CustomerVo;

/**
 * Implementation for CustomerDao
 * 
 * @author AIS
 */
public class CustomerDaoImpl extends BaseDaoImpl implements CustomerDao {

	public CustomerDaoImpl() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.css.crm.dao.CustomerDao#getCustomerByPK(java.lang.String)
	 */
	@Override
	public CustomerVo getCustomerByPK(String custId) {
		SqlSession session = getMyBatisSession();
		return (CustomerVo) session.selectOne("customer.getCustomerByPK", custId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.css.crm.dao.CustomerDao#insertCustomer(com.css.crm.vo.CustomerVo)
	 */
	@Override
	public int insertCustomer(CustomerVo customer) {
		SqlSession session = getMyBatisSession();
		return session.insert("customer.insertCustomer", customer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.css.crm.dao.CustomerDao#updateCustomerByPK(com.css.crm.vo.CustomerVo)
	 */
	@Override
	public int updateCustomerByPK(CustomerVo customer) {
		SqlSession session = getMyBatisSession();
		return session.update("customer.updateCustomerByPK", customer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.css.crm.dao.CustomerDao#deleteCustomerByPK(java.lang.String)
	 */
	@Override
	public int deleteCustomerByPK(String custId) {
		SqlSession session = getMyBatisSession();
		return session.delete("customer.deleteCustomerByPK", custId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.css.crm.dao.CustomerDao#getCustomerNextId(java.lang.Long)
	 */
	@Override
	public String getCustomerNextId(Long oriCtryCde) {
		SqlSession session = getMyBatisSession();
		CustomerVo customer = (CustomerVo) session.selectOne("customer.generateCustId", oriCtryCde);
		return customer.getCustId();

	}
}
